import { useEffect, useRef } from "react";

export const useMount = (cb: () => void) => {
  useEffect(() => {
    cb();
  }, []);
};

// 返回组件的挂载状态，如果还没挂载或者已经卸载，返回 false;反之，返回 true

export const useMountedRef = () => {
  const mountedRef = useRef(false);

  useEffect(() => {
    mountedRef.current = true;

    return () => {
      mountedRef.current = false;
    };
  });

  return mountedRef;
};
